{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8d1bce62",
   "metadata": {},
   "source": [
    "#### 使用列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "553d7d38",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f8d11208",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "717a8602",
   "metadata": {},
   "source": [
    "#### 在运行时“扩展”列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6169d837",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found = []\n",
    "len(found)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "10270755",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found.append('a')\n",
    "len(found)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "cb24464d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a']"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "eeb1c5c4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found.append('e')\n",
    "found.append('i')\n",
    "found.append('o')\n",
    "len(found)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "7b44f8d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'e', 'i', 'o']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6622f703",
   "metadata": {},
   "source": [
    "#### 用“in”检查成员关系"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9e730850",
   "metadata": {},
   "outputs": [],
   "source": [
    "if 'u'not in found:\n",
    "    found.append('u')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3f5e2235",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'e', 'i', 'o', 'u']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "3aac81ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "if 'u'not in found:\n",
    "    found.append('u')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4dc8914b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'e', 'i', 'o', 'u']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4107fc9d",
   "metadata": {},
   "source": [
    "#### 更新代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "adfac2dc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "        print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b9b32399",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e0ab639",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels: \")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf92d2b2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
